package com.hbnu.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hbnu.system.config.BaseException;
import com.hbnu.system.mapper.SocialEconomyMapper;
import com.hbnu.system.model.entity.SocialEconomy;
import com.hbnu.system.service.SocialEconomyService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class SocialEconomyServiceImpl extends ServiceImpl<SocialEconomyMapper, SocialEconomy> implements SocialEconomyService {
    @Override
    public boolean addSocialEconomy(SocialEconomy socialEconomy) {
        SocialEconomy socialEconomy1 = super.getOne(Wrappers.lambdaQuery(SocialEconomy.class)
                .eq(SocialEconomy::getSocialEconomyName,socialEconomy.getSocialEconomyName()));
        if(StrUtil.isEmpty(socialEconomy.getSocialEconomyName())||StrUtil.isBlank(socialEconomy.getSocialEconomyName())){
            throw new BaseException("该项目的社会经济目标名称为空");
        }
        if(!Objects.isNull(socialEconomy1)){
            throw new BaseException("该项目的社会经济目标名称已存在");
        }
        return baseMapper.insert(socialEconomy)==1;
    }

    @Override
    public List<SocialEconomy> getSocialEconomyList() {
        List<SocialEconomy> depts = baseMapper.selectList(Wrappers.lambdaQuery(SocialEconomy.class));
//        List<String> result = new ArrayList<>();
//        for (Dept dept : depts) {
//            result.add(dept.getDeptName());
//        }
        return depts;
    }

    @Override
    public boolean updateSocialEconomy(SocialEconomy projectcate) {
        return false;
    }

    @Override
    public boolean deleteSocialEconomy(String ID) {
        return baseMapper.deleteById(ID) == 1;
    }
}
